package controller.v2;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import model.AwardVO;
import model.BankVO;
import model.LogBuyCashVO;
import model.LogCashDrawVO;
import model.LogEarnVO;
import model.MemberVO;
import service.v2.AwardService;
import service.v2.BankService;
import service.v2.ConfigService;
import service.v2.MemberService;
import service.v2.MoneyService;
import util.NumberUtil;
import util.PackageUtil;
import util.PropertieUtil;
import util.StringUtil;

@RequestMapping("/v2/money")
@Controller
public class MoneyController {
	
	@Autowired
	private MoneyService moneyService;
	@Autowired
	private MemberService memberService;
	@Autowired
	private BankService bankService;
	@Autowired
	private AwardService awardService;
	@Autowired
	private ConfigService configService;
	
	/**
	 * 国际版提现帐户设置 PAYPAL
	 * inter_draw_paypal
	 */
	@ResponseBody
	@RequestMapping(value="/updatePayPal",method=RequestMethod.POST)
	public Object updatePayPal(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request
			, HttpServletResponse response,MemberVO memberVO){
		//验证密码
		if(memberVO.getInter_draw_paypal()==null){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		memberVO.setId(member_id);
		memberService.updatePayPal(memberVO);
		return PackageUtil.packageParams(200,"successs","",""); 
	}
	
	/**
	 * 国际版提现帐户设置 ALIPAY
	 * inter_draw_alipay
	 */
	@ResponseBody
	@RequestMapping(value="/updateAlipayInter",method=RequestMethod.POST)
	public Object updateAlipayInter(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request
			, HttpServletResponse response,MemberVO memberVO){
		//验证密码
		if(memberVO.getInter_draw_alipay()==null){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		memberVO.setId(member_id);
		memberService.updateInterAlipay(memberVO);
		return PackageUtil.packageParams(200,"successs","",""); 
	}
	
	/**
	 * 国际版提现帐户设置 bank
	 * inter_draw_bank_address
		inter_draw_bank_swift_code
		inter_draw_bank_no
		inter_draw_bank_aba
		inter_draw_bank_bsb
	 */
	@ResponseBody
	@RequestMapping(value="/updateBankInter",method=RequestMethod.POST)
	public Object updateBankInter(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request
			, HttpServletResponse response,MemberVO memberVO){
		//验证密码
		if(memberVO.getInter_draw_bank_address()==null || memberVO.getInter_draw_bank_swift_code()==null || memberVO.getInter_draw_bank_no()==null){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		memberVO.setId(member_id);
		memberService.updateInterBank(memberVO);
		return PackageUtil.packageParams(200,"successs","",""); 
	}
	
	/**
	 * 现金帐户
	 * @param token
	 * @param member_id
	 */
	@ResponseBody
	@RequestMapping(value="/moneyAccount",method=RequestMethod.GET)
	public Object moneyAccount(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO){
		
		MemberVO vo = memberService.getLoginMemberById(member_id);
		Map map = new HashMap();
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
			String unSettledMoney = moneyService.getUnSettledMoney(member_id);
			map.put("unSettledMoney", unSettledMoney);//待结算收益
			map.put("good_cash", vo.getGood_cash());//消费抵用金
			map.put("free_cash", vo.getFree_cash());//余额
			
			String unsettledmoney_en = moneyService.getUnSettledMoneyEn(member_id);
			map.put("unsettledmoney_en", unsettledmoney_en);
			map.put("good_cash_en", vo.getGood_cash());
			map.put("free_cash_en", vo.getFree_cash_en());
			map.put("inter_verify_state",vo.getInter_verify_state());
			
		map.put("incomeandexpenseslog",host+version+"/money/incomeAndExpensesLog");//收支明细
		//map.put("incomeandexpenseslog","http://10.0.0.68:8080/v2/money/incomeAndExpensesLog");
		map.put("unsettlement",host+version+"/money/unSettlement");//待结算收益
		//map.put("unsettlement","http://10.0.0.68:8080/v2/money/unSettlement");
		map.put("buycash",host+version+"/money/buyCash");//消费低佣金
		//map.put("buycash","http://10.0.0.68:8080/v2/money/buyCash");

		map.put("withdrawdeposit",host+version+"/money/withdrawDepositLog");//提现记录
		//map.put("withdrawdeposit","http://10.0.0.68:8080/v2/money/withdrawDepositLog");
		map.put("buy_cash_help_url",host+version+"/page/buyCashHelp");//消费抵用金使用帮助
		return PackageUtil.packageParams(200,"successs",map,""); 
	}
	
	/**
	 * 查询支付宝费率
	 * @param token
	 * @param member_id
	 */
	@ResponseBody
	@RequestMapping(value="/getAlipayFee",method=RequestMethod.GET)
	public Object getAlipayFee(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO){
		String fee = memberService.getAlipayFee("Alipay");
		return PackageUtil.packageParams(200,"successs",fee,""); 
	}
	
	/**
	 * 查询现金帐户
	 * @param token
	 * @param member_id
	 */
	@ResponseBody
	@RequestMapping(value="/getDrawAccount",method=RequestMethod.GET)
	public Object getDrawAccount(@RequestHeader (value="LANG", required=false) String lang,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO){
		if(lang==null){
			memberVO = memberService.getDrawAccount(member_id);
		}else{
			memberVO = memberService.getDrawAccountInter(member_id);
		}
		return PackageUtil.packageParams(200,"successs",memberVO,""); 
	}
	
	
	/**
	 * 查询银行列表
	 * @param token
	 * @param member_id
	 */
	@ResponseBody
	@RequestMapping(value="/getBankList",method=RequestMethod.GET)
	public Object getBankList(@RequestHeader (value="LANG", required=false) String lang,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO){
		List<BankVO> list = bankService.getBankList();
		return PackageUtil.packageParams(200,"successs",list,""); 
	}
	
	/**
	 * 查询银行列表国际版
	 * @param token
	 * @param member_id
	 */
	@ResponseBody
	@RequestMapping(value="/getInterBankList",method=RequestMethod.GET)
	public Object getInterBankList(@RequestHeader (value="LANG", required=false) String lang,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO){
		List<BankVO> list = bankService.getInterDrawBankList();
		return PackageUtil.packageParams(200,"successs",list,""); 
	}
	
	/**
	 *修改提现帐户
	 * @param token
	 * @param member_id
	 * @param type 1支付宝  2银行
	 * @param account 帐号
	 * @param name 姓名
	 * @param bank_id 银行ID
	 */
	@ResponseBody
	@RequestMapping(value="/updateDrawAccount",method=RequestMethod.POST)
	public Object updateDrawAccount(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response
			,MemberVO memberVO, String type,String account,String name,String bank_id){
		
		//验证参数
		if(type==null||"".equals(type)||account==null||"".equals(account) || name==null||"".equals(name) || name.length() > 20 || account.length() > 50){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if("2".equals(type) && (bank_id==null||"".equals(bank_id))){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		//检查实名
		memberVO = memberService.getAllInfoById(member_id);
		if(!name.equals(memberVO.getName())){
			return PackageUtil.packageParams(12006,"提现账户姓名与会员姓名不符","",""); 
		}
		//验证类型
		if(!"1".equals(type) && !"2".equals(type) ){
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		if("2".equals(type)){
			//验证银行ID
			BankVO bankVO = bankService.getBankById(bank_id);
			if(bankVO==null){
				return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
			}
		}
		//修改提现帐户
		memberService.updateDrawAccountAlipay(member_id,type,account, name,bank_id);
		return PackageUtil.packageParams(200,"successs","",""); 
	}
	
	/**
	 * 支付密码验证
	 * @param token
	 * @param member_id
	 * @param pay_pwd
	 * return 0错误 1正确
	 */
	@ResponseBody
	@RequestMapping(value="/checkPayPwd",method=RequestMethod.GET)
	public Object checkPayPwd(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO){
	
		//验证密码
		if(memberVO.getPay_pwd()==null || memberVO.getPay_pwd().length() != 32){
			return PackageUtil.packageParams(10705,"密码格式错误","",""); 
		}
		memberVO.setId(member_id);
		int total = memberService.chekPayPwd(memberVO);
		return PackageUtil.packageParams(200,"successs",total,""); 
	}
	
	/**
	 * 计算手续费
	 * @param token
	 * @param member_id
	 */
	@ResponseBody
	@RequestMapping(value="/calcDrawFee",method=RequestMethod.GET)
	public Object calcDrawFee(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id
			,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO, String free_cash, String type){
		//验证参数
		if(type==null||"".equals(type)||free_cash==null||"".equals(free_cash) ){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		//验证类型
		if(!"1".equals(type) && !"2".equals(type) ){
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		if(!StringUtil.isPrice(free_cash)){ 
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		memberVO = memberService.getAllInfoById(member_id);
		//提现帐户
		if(("1".equals(type) && memberVO.getAlipay()==null) || ("2".equals(type) && memberVO.getBank_card()==null)){
			return PackageUtil.packageParams(12001,"提现账户不存在","","");  
		}
		double fee = moneyService.calcFee(type,member_id,free_cash);
		return PackageUtil.packageParams(200,"successs",NumberUtil.formatDouble(fee, 2)+"",""); 
	}
	
	/**
	 * 计算手续费 国际版
	 * @param token
	 * @param member_id
	 * bank_id 
	 * free_cash
	 */
	@ResponseBody
	@RequestMapping(value="/calcDrawFeeInter",method=RequestMethod.GET)
	public Object calcDrawFeeInter(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id
			,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO, String free_cash, String bank_id){
		//验证参数
		if(free_cash==null||"".equals(free_cash) || bank_id == null ){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if(!StringUtil.isPrice(free_cash)){ 
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		BankVO bankVO = moneyService.getDrawBank(bank_id);
		if(bankVO == null){
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		memberVO = memberService.getAllInfoById(member_id);
		double fee = moneyService.calcFeeDetail(free_cash,bankVO);
		return PackageUtil.packageParams(200,"successs",NumberUtil.formatDouble(fee, 2)+"",""); 
	}
	
	/**
	 * 提现订单生成
	 * @param token
	 * @param member_id
	 * @param type 1支付宝  2银行
	 * @param free_cash 金额
	 * @param pay_pwd 支付密码
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value="/drawMoney",method=RequestMethod.POST)
	public Object drawMoney(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response
			,MemberVO memberVO, String type,String free_cash,String pay_pwd) throws Exception{
		
		//验证参数
		if(type==null||"".equals(type)||free_cash==null||"".equals(free_cash) || pay_pwd==null||"".equals(pay_pwd) ){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		//验证类型
		if(!"1".equals(type) && !"2".equals(type) ){
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		if(!StringUtil.isPrice(free_cash)){ 
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		//验证密码
		if(pay_pwd==null || pay_pwd.length() != 32){
			return PackageUtil.packageParams(10705,"密码格式错误","",""); 
		}
		//密码错误
		memberVO.setId(member_id);
		int total = memberService.chekPayPwd(memberVO);
		if(total==0){
			return PackageUtil.packageParams(12005,"支付密码错误","",""); 
		}
		//余额不足
		int num = memberService.checkFreeCash(memberVO);
		if(num == 0){
			return PackageUtil.packageParams(12002,"账户余额不足","",""); 
		}
		//检查提现帐户
		boolean flag = memberService.checkRealName(type,member_id);
		if(!flag){
			return PackageUtil.packageParams(12006,"提现账户姓名与会员姓名不符","",""); 
		}
		//检查实名认证状态
		memberVO = memberService.getAllInfoById(member_id);
		if(!"4".equals(memberVO.getIdcard_state())){
			return PackageUtil.packageParams(12006,"实名认证状态不正确","",""); 
		}
		//提现帐户
		if(("1".equals(type) && memberVO.getAlipay()==null) || ("2".equals(type) && memberVO.getBank_card()==null)){
			return PackageUtil.packageParams(12001,"提现账户不存在","","");  
		}
		//限制区代一个月内的不能提现
		if(PropertieUtil.loadPropertie("proxy_identify").equals(memberVO.getIdentity())){
			double profit = memberService.getCurMonthProfit(member_id);
			if(Double.parseDouble(memberVO.getFree_cash()) - Double.parseDouble(free_cash) < profit){
				return PackageUtil.packageParams(12007,"本月利润请下个月再提取","",""); 
			}
		}
	
		LogCashDrawVO drawVO = new LogCashDrawVO();
		//生成提现订单 减掉余额
		int re = moneyService.insertDraw(drawVO,member_id,type,free_cash);
		if(re > 0){
			return PackageUtil.packageParams(200,"successs","",""); 
		}else{
			return PackageUtil.packageParams(12003,"创建提现订单失败","",""); 
		}
	}
	
	/**
	 * 国际版提现订单生成
	 * @param token
	 * @param member_id
	 * @param type 1支付宝  2PayPal 3银行卡
	 * @param free_cash 金额
	 * @param pay_pwd 支付密码
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value="/drawMoneyInter",method=RequestMethod.POST)
	public Object drawMoneyInter(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request, HttpServletResponse response
			,MemberVO memberVO, String type,String free_cash,String pay_pwd) throws Exception{
		
		//验证参数
		if(type==null||"".equals(type)||free_cash==null||"".equals(free_cash) || pay_pwd==null||"".equals(pay_pwd) ){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		//验证类型
		if(!"1".equals(type) && !"2".equals(type) && !"3".equals(type) ){
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		if(!StringUtil.isPrice(free_cash)){ 
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		//验证密码
		if(pay_pwd==null || pay_pwd.length() != 32){
			return PackageUtil.packageParams(10705,"密码格式错误","",""); 
		}
		//密码错误
		memberVO.setId(member_id);
		int total = memberService.chekPayPwd(memberVO);
		if(total==0){
			return PackageUtil.packageParams(12005,"支付密码错误","",""); 
		}
		//余额不足
		int num = memberService.checkFreeCashEn(memberVO);
		if(num == 0){
			return PackageUtil.packageParams(12002,"账户余额不足","",""); 
		}
		//检查实名认证
		memberVO = memberService.getAllInfoById(member_id);
		if(!"4".equals(memberVO.getInter_verify_state())){
			return PackageUtil.packageParams(12006,"未实名认证","",""); 
		}
		//提现帐户
		if(("1".equals(type) && memberVO.getInter_draw_alipay()==null) || ("2".equals(type) && memberVO.getInter_draw_paypal()==null)
				 || ("3".equals(type) && memberVO.getInter_draw_bank_no()==null)
				){
			return PackageUtil.packageParams(12001,"提现账户不存在","","");  
		}
		//限制区代一个月内的不能提现
//		if(PropertieUtil.loadPropertie("proxy_identify").equals(memberVO.getIdentity())){
//			double profit = memberService.getCurMonthProfitInter(member_id);
//			if(Double.parseDouble(memberVO.getFree_cash()) - Double.parseDouble(free_cash) < profit){
//				return PackageUtil.packageParams(12007,"本月利润请下个月再提取","",""); 
//			}
//		}
	
		LogCashDrawVO drawVO = new LogCashDrawVO();
		//生成提现订单 减掉余额
		int re = moneyService.insertDrawInter(drawVO,member_id,type,free_cash);
		if(re > 0){
			return PackageUtil.packageParams(200,"successs","",""); 
		}else{
			return PackageUtil.packageParams(12003,"创建提现订单失败","",""); 
		}
	}
	
	/**
	 * 提现记录
	 * @param token
	 * @param member_id
	 * @param page_index
	 */
	@RequestMapping(value="/withdrawDepositLog",method=RequestMethod.GET)
	public String withdrawDeposit(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,
			HttpServletRequest request, HttpServletResponse response,MemberVO memberVO,LogEarnVO logEarnVO,String isJSON)throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		
		int total = moneyService.getWithdrawDepositTotal(member_id,lang);
		logEarnVO.setPagination(logEarnVO.getPage_index(), total+"");
		List<LogEarnVO> withdrawDeposit_Log = moneyService.selectWithdrawDepositLog(member_id,logEarnVO,lang);
		if(!"1".equals(isJSON)){
			
			request.setAttribute("withdrawDeposit_Log", withdrawDeposit_Log);
			request.setAttribute("token", token);
			request.setAttribute("memberId", member_id);
			request.setAttribute("os", os);
			request.setAttribute("withdrawdepositlogone_url",host+version+"/money/withdrawDepositLogOne");
			//request.setAttribute("withdrawdepositlogone_url","http://10.0.0.68:8080/v2/money/withdrawDepositLogOne");
			request.setAttribute("host_url",host);
			return "/app/money/withdrawDepositLog"; 
		}else{
			Map map  =  new HashMap();
			LogEarnVO pagination = moneyService.packPaginationInfo(logEarnVO);
			 map.put("pagination", pagination);
			 map.put("withdrawDeposit_Log", withdrawDeposit_Log);
			 map.put("pagination", logEarnVO);
			 map.put("token", token);
			 map.put("memberId", member_id);
			 map.put("os", os);
			 map.put("withdrawdepositlogone_url",host+version+"/money/withdrawDepositLogOne");
			 map.put("host_url",host);
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	      return null;
		}
	}
	
	/**
	 * 提现记录子页
	 * @param token
	 * @param member_id
	 * @param page_index
	 */
	@RequestMapping(value="/withdrawDepositItem",method=RequestMethod.GET)
	public String withdrawDepositItem(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,
			HttpServletRequest request, HttpServletResponse response,MemberVO memberVO,LogEarnVO logEarnVO,String isJSON)throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		int total = moneyService.getWithdrawDepositTotal(member_id,lang);	
		logEarnVO.setPagination(logEarnVO.getPage_index(), total+"");
		List<LogEarnVO> withdrawDeposit_Log = moneyService.selectWithdrawDepositLog(member_id,logEarnVO,lang);
		if(!"1".equals(isJSON)){
			
			request.setAttribute("withdrawDeposit_Log", withdrawDeposit_Log);
			request.setAttribute("pagination", logEarnVO);
			request.setAttribute("token", token);
			request.setAttribute("os", os);
			request.setAttribute("memberId", member_id);
			request.setAttribute("withdrawdepositlogone_url",host+version+"/money/withdrawDepositLogOne");
			return "/app/money/withdrawDepositItem"; 
			
		}else{
			Map map  =  new HashMap();
			LogEarnVO pagination = moneyService.packPaginationInfo(logEarnVO);
			map.put("pagination", pagination);
			map.put("withdrawDeposit_Log", withdrawDeposit_Log);
			map.put("pagination", logEarnVO);
			map.put("token", token);
			map.put("os", os);
			map.put("memberId", member_id);
			map.put("withdrawdepositlogone_url",host+version+"/money/withdrawDepositLogOne");
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
		    return null;
			
		}
	}	
	
	/**
	 * 交易明细
	 * @param token
	 * @param member_id
	 * @param logcashdraw_id
	 * @throws IOException 
	 */
	@RequestMapping(value="/withdrawDepositLogOne",method=RequestMethod.GET)
	public String withdrawDepositLogOne(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  
	String member_id,HttpServletRequest request, HttpServletResponse response,String withdrawDeposit_id,MemberVO memberVO) throws IOException{
			//验证参数
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		if(withdrawDeposit_id==null||"".equals(withdrawDeposit_id)){
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10001,"缺少必选参数","","")) );
			out.flush();
			out.close();
			return null;
		}
		
		int re = moneyService.selectMemberById(withdrawDeposit_id,member_id);
		if(re == 0){
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10000,"参数错误，请参考API文档","","")) );
			out.flush();
			out.close();
			return null;
		}
		LogEarnVO LogCashDrawOne = moneyService.selectWithdrawDepositLogOne(member_id,withdrawDeposit_id);
		if(lang ==null){
			request.setAttribute("LogCashDrawOne", LogCashDrawOne);
			request.setAttribute("host_url",host);
			request.setAttribute("os", os);
			request.setAttribute("withdrawdepositlogone_url",host+version+"/money/withdrawDepositLogOne");
			//request.setAttribute("withdrawdepositlogone_url","http://10.0.0.68:8080/v2/money/withdrawDepositLogOne");
			request.setAttribute("wechat_host",configService.loadConfig("WECHAT_HOST"));
			return "/app/money/withdrawDepositLogDetail"; 
		}else{
			Map map = new HashMap();
			map.put("LogCashDrawOne", LogCashDrawOne);
			map.put("host_url",host);
			map.put("os", os);
			map.put("withdrawdepositlogone_url",host+version+"/money/withdrawDepositLogOne");
			map.put("wechat_host",configService.loadConfig("WECHAT_HOST"));

			response.setContentType("text/html;charset=utf-8");
			PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        return null;
		}
	}
	/**
	 * 购物专佣金
	 * @param token
	 * @param member_id
	 * @param bill_type(1:入账 2,3:支出 )
	 * @param type(1奖项获得2退款3购物)
	 * @param page_index
	 * @throws IOException 
	 */
	@RequestMapping(value="/buyCash",method=RequestMethod.GET)
	public String buyCash(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,LogBuyCashVO logBuyCashVO,String isJSON) throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		
		logBuyCashVO.setMember_id(member_id);
		int total = moneyService.getTotal(logBuyCashVO);
		logBuyCashVO.setPagination(logBuyCashVO.getPage_index(),total+"");
		logBuyCashVO.setLang(lang);
		List<LogBuyCashVO> logBuyCashScreenList = moneyService.selectLogBuyCashList(logBuyCashVO);
		
		if(!"1".equals(isJSON)){
			request.setAttribute("logBuyCashScreenList", logBuyCashScreenList);	
			request.setAttribute("pagination", logBuyCashVO); 
			request.setAttribute("logBuyCashVO", logBuyCashVO); 
			request.setAttribute("token", token);
			request.setAttribute("memberId", member_id);
			request.setAttribute("os", os);
			request.setAttribute("buycashone_url",host+version+"/money/buyCashOne");
			//request.setAttribute("buycashone_url","http://10.0.0.68:8080/v2/money/buyCashOne");
			request.setAttribute("buycashheleppage_url",host+version+"/page/buyCashHelp");
			request.setAttribute("host_url",host);
			return "/app/money/buyCash";
		}else{
			Map map  =  new HashMap();
			LogBuyCashVO pagination = moneyService.packPaginationInfo(logBuyCashVO);
			 map.put("pagination", pagination);
			 map.put("logBuyCashScreenList", logBuyCashScreenList);	
			 map.put("pagination", logBuyCashVO); 
			 map.put("logBuyCashVO", logBuyCashVO); 
			 map.put("token", token);
			 map.put("memberId", member_id);
			 map.put("os", os);
			 map.put("buycashone_url",host+version+"/money/buyCashOne");
			 map.put("buycashheleppage_url",host+version+"/page/buyCashHelp");
			 map.put("host_url",host);
			
			response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
		    return null;
		}

	}
	
	/**
	 * 消费低佣金交易明细
	 * @param token
	 * @param member_id
	 * @param logByCashId
	 * @throws IOException 
	 */

	@RequestMapping(value="/buyCashOne",method=RequestMethod.GET)
	public String buyCashOne(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,String logByCashId,MemberVO memberVO,LogBuyCashVO logBuyCashVO) throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		String wechat_host=configService.loadConfig("WECHAT_HOST");
		//验证参数
		if(logByCashId==null||"".equals(logByCashId)){
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10001,"缺少必选参数","","")) );
			out.flush();
			out.close();
			return null;
		}
		int re = moneyService.checkLogBuyCashById(logByCashId);
		
		if(re==0){
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10000,"参数错误，请参考API文档","","")) );
			out.flush();
			out.close();
			return null;
		}
		//交易明细
		LogBuyCashVO LogBuyCashOne = moneyService.selectLogBuyCashOne(logByCashId,member_id);
		if(lang ==null){
			request.setAttribute("LogBuyCashOne", LogBuyCashOne);
			//兑换券名称从数据库查出来。
			request.setAttribute("ticket_name",configService.loadConfig("TICKET_NAME"));
			request.setAttribute("host_url",host);
			request.setAttribute("wechat_host",wechat_host);
			request.setAttribute("shopping_money_name",configService.loadConfig("SHOPPING_MONEY_NAME"));
			request.setAttribute("os", os);
			request.setAttribute("buycashone_url",host+version+"/money/buyCashOne");
			request.setAttribute("wechat_host",wechat_host);

			return "/app/money/buyCashDetail";
		}else{
			Map map = new HashMap();
			map.put("ticket_name",configService.loadConfig("TICKET_NAME"));
			map.put("host_url",host);
			map.put("shopping_money_name",configService.loadConfig("SHOPPING_MONEY_NAME"));
			map.put("wechat_host",wechat_host);
			map.put("os", os);
			map.put("buycashone_url",host+version+"/money/buyCashOne");
			map.put("wechat_host",wechat_host);
			map.put("LogBuyCashOne", LogBuyCashOne);


			response.setContentType("text/html;charset=utf-8");
			PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        return null;	
		}
		
	}

	
	/**
	 * 低佣金明细筛选
	 */	
	@RequestMapping(value="/buyCashScreen",method=RequestMethod.GET)
	public String buyCashScreen(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO, LogBuyCashVO logBuyCashVO,String isJSON)throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		logBuyCashVO.setMember_id(member_id);
		logBuyCashVO.setLang(lang);
		int total = moneyService.getTotal(logBuyCashVO);
		logBuyCashVO.setPagination(logBuyCashVO.getPage_index(),total+"");
		List<LogBuyCashVO> logBuyCashScreenList = moneyService.selectLogBuyCashList(logBuyCashVO);
		
		if(!"1".equals(isJSON)){
			request.setAttribute("logBuyCashScreenList", logBuyCashScreenList);	
			request.setAttribute("pagination", logBuyCashVO); 
			request.setAttribute("logBuyCashVO", logBuyCashVO); 
			request.setAttribute("os", os); 
			request.setAttribute("token", token);
			request.setAttribute("memberId", member_id);
			request.setAttribute("buycashone_url",host+version+"/money/buyCashOne");
			//request.setAttribute("buycashone_url","http://10.0.0.68:8080/v2/money/buyCashOne");

			request.setAttribute("buycashheleppage_url",host+version+"/page/buyCashHelp");
			return "/app/money/buyCashScreen";
		}else{
			Map map  =  new HashMap();
			LogBuyCashVO pagination = moneyService.packPaginationInfo(logBuyCashVO);
			 map.put("pagination", pagination);
			 map.put("logBuyCashScreenList", logBuyCashScreenList);	
			 map.put("pagination", logBuyCashVO); 
			 map.put("logBuyCashVO", logBuyCashVO); 
			 map.put("os", os); 
			 map.put("token", token);
			 map.put("memberId", member_id);
			 map.put("buycashone_url",host+version+"/money/buyCashOne");
			 map.put("buycashheleppage_url",host+version+"/page/buyCashHelp");
			
			response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
		    return null;
		}
	}

	/**
	 * 低佣金明细子页
	 */	
	@RequestMapping(value="/buyCashScreenItem",method=RequestMethod.GET)
	public String buyCashScreenItem(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO, LogBuyCashVO logBuyCashVO,String isJSON)throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		logBuyCashVO.setMember_id(member_id);
		logBuyCashVO.setLang(lang);
		int total = moneyService.getTotal(logBuyCashVO);
		logBuyCashVO.setPagination(logBuyCashVO.getPage_index(),total+"");
		List<LogBuyCashVO> logBuyCashScreenList = moneyService.selectLogBuyCashList(logBuyCashVO);
		
		if(!"1".equals(isJSON)){
			request.setAttribute("logBuyCashScreenList", logBuyCashScreenList);	
			request.setAttribute("pagination", logBuyCashVO); 
			request.setAttribute("logBuyCashVO", logBuyCashVO); 
			request.setAttribute("token", token);
			request.setAttribute("os", os);
			request.setAttribute("memberId", member_id);
			request.setAttribute("buycashone_url",host+version+"/money/buyCashOne");
			//request.setAttribute("buycashone_url","http://10.0.0.68:8080/v2/money/buyCashOne");

			request.setAttribute("buycashheleppage_url",host+version+"/page/buyCashHelp");
			return "/app/money/buyCashItem";
		}else{
			Map map  =  new HashMap();
			 map.put("logBuyCashScreenList", logBuyCashScreenList);	
			 map.put("pagination", logBuyCashVO); 
			 map.put("logBuyCashVO", logBuyCashVO); 
			 map.put("token", token);
			 map.put("os", os);
			 map.put("memberId", member_id);
			 map.put("buycashone_url",host+version+"/money/buyCashOne");
			 map.put("buycashheleppage_url",host+version+"/page/buyCashHelp");
			
			response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
		    return null;
		}
	}
	/**
	 * 待结算收益
	 * @param token
	 * @param member_id
	 * @param page_index
	 * @throws IOException 
	 */
	@RequestMapping(value="/unSettlement",method=RequestMethod.GET)
	public String unSettlement(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,LogEarnVO logEarnVO,String isJSON) throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		
		int total = moneyService.getUnSettlementTotal(member_id,lang);
		logEarnVO.setPagination(logEarnVO.getPage_index(),total+"");
		
		List<LogEarnVO> logearnList = moneyService.selectUnSettlementList(member_id,logEarnVO,lang);
		
		if(!"1".equals(isJSON)){
			request.setAttribute("logearnList", logearnList);
			request.setAttribute("pagination", logEarnVO);
			request.setAttribute("token",token);
			request.setAttribute("memberId",member_id);
			request.setAttribute("os",os);
			request.setAttribute("unSettlementOne_url",host+version+"/money/unSettlementOne");
			//request.setAttribute("unSettlementOne_url","http://10.0.0.68:8080/v2/money/unSettlementOne");
			request.setAttribute("host_url",host);
			
		}else{
			Map map  =  new HashMap();
			LogEarnVO pagination = moneyService.packPaginationInfo(logEarnVO);
			 map.put("pagination", pagination);
			 map.put("logearnList", logearnList);
			 map.put("pagination", logEarnVO);
			 map.put("token",token);
			 map.put("memberId",member_id);
			 map.put("os",os);
			 map.put("unSettlementOne_url",host+version+"/money/unSettlementOne");
			 map.put("host_url",host);
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	        return null;
		}
		return "/app/money/settlement";
	}

	/**
	 * 待结算收益子页
	 * @param token
	 * @param member_id
	 * @param page_index
	 * @throws IOException 
	 */
	@RequestMapping(value="/unSettlementItem",method=RequestMethod.GET)
	public String unSettlementItem(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,LogEarnVO logEarnVO,String isJSON) throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");

		int total = moneyService.getUnSettlementTotal(member_id,lang);
		logEarnVO.setPagination(logEarnVO.getPage_index(),total+"");
		
		List<LogEarnVO> logearnList = moneyService.selectUnSettlementList(member_id,logEarnVO,lang);
		
		if(!"1".equals(isJSON)){
			request.setAttribute("logearnList", logearnList);
			request.setAttribute("pagination", logEarnVO);
			request.setAttribute("token",token);
			request.setAttribute("memberId",member_id);
			request.setAttribute("os",os);
			request.setAttribute("unSettlementOne_url",host+version+"/money/incomeAndExpensesLogOne");
			//request.setAttribute("unSettlementOne_url","http://10.0.0.68:8080/v2/money/unSettlementOne");

			return "/app/money/settlementItem";
		}else{
			Map map  =  new HashMap();
			LogEarnVO pagination = moneyService.packPaginationInfo(logEarnVO);
			 map.put("pagination", pagination);
			 map.put("logearnList", logearnList);
			 map.put("pagination", logEarnVO);
			 map.put("token",token);
			 map.put("memberId",member_id);
			 map.put("os",os);
			 map.put("unSettlementOne_url",host+version+"/money/incomeAndExpensesLogOne");
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	      return null;
		}
		
	}	
	
	
	/**
	 * 待结算收益交易明细
	 * @param token
	 * @param member_id
	 * @param unSettlement_id
	 */
	@RequestMapping(value="/unSettlementOne",method=RequestMethod.GET)
	public String unSettlementOne(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,String unSettlement_id,LogEarnVO logEarnVO)throws IOException{
		
		//验证参数
		if(unSettlement_id==null||"".equals(unSettlement_id)){
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10001,"缺少必选参数","","")) );
			out.flush();
			out.close();
			return null;
		}

		int re = moneyService.checkUnSettlementOneById(unSettlement_id);
		
		if(re==0){
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10000,"参数错误，请参考API文档","","")) );
			out.flush();
			out.close();
			return null;
		}
		String host = configService.loadConfig("HOST");
		String ticket_name = configService.loadConfig("TICKET_NAME");
		String shopping_money_name = configService.loadConfig("SHOPPING_MONEY_NAME");
		
		memberVO = memberService.selectmMemberTable(member_id);
		LogEarnVO LogEarnOne = moneyService.selectUnSettlementOne(unSettlement_id,member_id);
		if(lang ==null){
			request.setAttribute("LogEarnOne", LogEarnOne);
			request.setAttribute("memberInfo", memberVO);
			//兑换券名称从数据库查出来。
			request.setAttribute("ticket_name",ticket_name);
			request.setAttribute("host_url",host);
			request.setAttribute("shopping_money_name",shopping_money_name);
			return "/app/money/settlementDetail";
		}else{
			Map map = new HashMap();
			map.put("LogEarnOne", LogEarnOne);
			map.put("memberInfo", memberVO);
			map.put("ticket_name",ticket_name);
			map.put("host_url",host);
			map.put("shopping_money_name",shopping_money_name);

			response.setContentType("text/html;charset=utf-8");
			PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        return null;
		}
		
	}
	/**
	 * 收支明细
	 * @param token
	 * @param member_id
	 * @param bill_type(1:出账 2 :入账))
	 * @param page_index
	 * @throws IOException 
	 */
	@RequestMapping(value="/incomeAndExpensesLog",method=RequestMethod.GET)
	public String incomeAndExpensesLog(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,String bill_type,String award_id,String type,LogEarnVO logEarnVO,AwardVO awardVO,String isJSON,String incom_change) throws IOException{
		/*os="ios";
		member_id="1567";
		token="196db0eb5e68cb34f6266d321b12580a";*/
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		String ticket_name=configService.loadConfig("TICKET_NAME");
		memberVO = memberService.selectmMemberTable(member_id);
		List<AwardVO>  awardList = awardService.getAwardList(memberVO.getLevel());
		logEarnVO.setMember_id(member_id);
		logEarnVO.setAward_id(award_id);
		logEarnVO.setLang(lang);
		int total = moneyService.getIncomeAndExpensesTotal(logEarnVO);
		logEarnVO.setPagination(logEarnVO.getPage_index(),total+"");
		List<LogEarnVO> incomeAndExpensesList = moneyService.selectIncomeAndExpensesList(logEarnVO);
		
		if(!"1".equals(isJSON)){
			request.setAttribute("awardList",awardList);
			request.setAttribute("incomeAndExpensesList", incomeAndExpensesList);
			request.setAttribute("pagination", logEarnVO);
			request.setAttribute("token", token);
			request.setAttribute("memberId", member_id);
			request.setAttribute("os",os);
			request.setAttribute("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");
			//request.setAttribute("incomeAndExpensesLogOne_url","http://10.0.0.68:8080/v2/money/incomeAndExpensesLogOne");
			//兑换券名称从数据库查出来。
			request.setAttribute("ticket_name",ticket_name);
			
			request.setAttribute("host_url",host);
			request.setAttribute("incom_change",incom_change);
			return "/app/money/incomeAndExpensesLog";
		}else{
			Map map  =  new HashMap();
			LogEarnVO pagination = moneyService.packPaginationInfo(logEarnVO);
			 map.put("pagination", pagination);
			 map.put("awardList",awardList);
			 map.put("incomeAndExpensesList", incomeAndExpensesList);
			 map.put("pagination", logEarnVO);
			 map.put("token", token);
			 map.put("memberId", member_id);
			 map.put("os",os);
			 map.put("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");
			 map.put("ticket_name",ticket_name);
			
			 map.put("host_url",host);
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	      return null;
		}
		
	}
	/**
	 * 收支交易明细
	 * @param token
	 * @param member_id
	 * @param incomeAndExpenses_id
	 * @throws IOException 
	 */
	@RequestMapping(value="/incomeAndExpensesLogOne",method=RequestMethod.GET)
	public String incomeAndExpensesLogOne(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,String incomeAndExpenses_id,LogEarnVO logEarnVO) throws IOException{
		//验证参数
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		String wechat_host=configService.loadConfig("WECHAT_HOST");
		String ticket_name=configService.loadConfig("TICKET_NAME");
		
    	if(incomeAndExpenses_id==null||"".equals(incomeAndExpenses_id)){
    		response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10001,"缺少必选参数","","")) );
			out.flush();
			out.close();
			return null;
		} 
		int re =moneyService.checkIncomeAndExpensesOne(member_id,incomeAndExpenses_id);
		
		if(re==0){
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter out = response.getWriter(); 
			out.print(JSON.toJSONString(PackageUtil.packageParams(10000,"参数错误，请参考API文档","","")) );
			out.flush();
			out.close();
			return null;
		}
		memberVO = memberService.selectmMemberTable(member_id);
		LogEarnVO incomeAndExpensesOne = moneyService.selectIncomeAndExpensesOne(member_id,incomeAndExpenses_id);
		if(lang ==null){
			request.setAttribute("incomeAndExpensesOne", incomeAndExpensesOne);
			request.setAttribute("membeInfo", memberVO);
			//兑换券名称从数据库查出来。
			request.setAttribute("ticket_name",ticket_name);
			request.setAttribute("host_url",host);
			request.setAttribute("wechat_host",wechat_host);
			request.setAttribute("shopping_money_name",configService.loadConfig("SHOPPING_MONEY_NAME"));
			request.setAttribute("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");
			//request.setAttribute("incomeAndExpensesLogOne_url","http://10.0.0.68:8080/v2/money/incomeAndExpensesLogOne");
			request.setAttribute("os",os);

			return "/app/money/incomeAndExpensesLogDetail";
		}else{
			Map map  =  new HashMap();
			 map.put("incomeAndExpensesOne", incomeAndExpensesOne);
			 map.put("membeInfo", memberVO);
			 map.put("ticket_name",ticket_name);
			 map.put("host_url",host);
			 map.put("wechat_host",wechat_host);
			 map.put("shopping_money_name",configService.loadConfig("SHOPPING_MONEY_NAME"));
			 map.put("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");
			 map.put("os",os);
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	      return null;
		}
		
	}
	
	/**
	 * 收支明细 条件查询returen页面
	 * @param token
	 * @param member_id
	 * @param bill_type(1:出账 2 :入账)
	 * @param type(1:余额充值  3:退款  4:余额提现 5:购物 6:兑换券充值 7:会员升级)
	 * @param award_id(1,2,3,4,5)
	 * @param page_index
	 */
	@RequestMapping(value="/incomeAndExpensesList",method=RequestMethod.GET)
	public String incomeAndExpensesList(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,String bill_type,String award_id,String type,LogEarnVO logEarnVO,AwardVO awardVO,String isJSON)throws IOException{
		
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		String ticket_name=configService.loadConfig("TICKET_NAME");

		logEarnVO.setMember_id(member_id);
		logEarnVO.setAward_id(award_id);
		logEarnVO.setLang(lang);
		memberVO = memberService.selectmMemberTable(member_id);
		List<AwardVO>  awardList = awardService.getAwardList(memberVO.getLevel());
				if(award_id !=null){
			String awardName = moneyService.getawardName(award_id);
			request.setAttribute("awardName", awardName);
		}
		
		int total = moneyService.getIncomeAndExpensesTotal(logEarnVO);
		logEarnVO.setPagination(logEarnVO.getPage_index(),total+"");
		List<LogEarnVO> incomeAndExpensesList = moneyService.selectIncomeAndExpensesList(logEarnVO);
		if(!"1".equals(isJSON)){
			request.setAttribute("awardList",awardList);
			request.setAttribute("incomeAndExpensesList", incomeAndExpensesList);
			request.setAttribute("token", token);
			request.setAttribute("memberId", member_id);
			request.setAttribute("type", type);
			request.setAttribute("bill_type",bill_type);
			request.setAttribute("award_id",award_id);
			request.setAttribute("os",os);
			request.setAttribute("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");
			//request.setAttribute("incomeAndExpensesLogOne_url","http://10.0.0.68:8080/v2/money/incomeAndExpensesLogOne");

			//兑换券名称从数据库查出来。
			request.setAttribute("ticket_name",ticket_name);
			request.setAttribute("logEarn", logEarnVO);
			return "/app/money/incomeAndExpensesList";
		}else{
			Map map  =  new HashMap();
			LogEarnVO pagination = moneyService.packPaginationInfo(logEarnVO);
			 map.put("pagination", pagination);
			map.put("awardList",awardList);
			map.put("incomeAndExpensesList", incomeAndExpensesList);
			map.put("token", token);
			map.put("memberId", member_id);
			map.put("type", type);
			map.put("bill_type",bill_type);
			map.put("award_id",award_id);
			map.put("os",os);
			map.put("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");

			//兑换券名称从数据库查出来。
			map.put("ticket_name",ticket_name);
			map.put("logEarn", logEarnVO);
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	      return null;
		}
		
	}	
	
	
	/**
	 *收支明细子页
	 */	
	@RequestMapping(value="/incomeAndExpensesItem",method=RequestMethod.GET)
	public String incomeAndExpensesItem(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,HttpServletRequest request,
			HttpServletResponse response,MemberVO memberVO,String bill_type,String award_id,String type,LogEarnVO logEarnVO,AwardVO awardVO,String isJSON)throws IOException{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		String ticket_name=configService.loadConfig("TICKET_NAME");

		logEarnVO.setMember_id(member_id);
		logEarnVO.setAward_id(award_id);
		logEarnVO.setLang(lang);
		memberVO = memberService.selectmMemberTable(member_id);
		List<AwardVO>  awardList = awardService.getAwardList(memberVO.getLevel()); 
		if(award_id !=null){
			String awardName = moneyService.getawardName(award_id);
			request.setAttribute("awardName", awardName);
		}
		int total = moneyService.getIncomeAndExpensesTotal(logEarnVO);
		logEarnVO.setPagination(logEarnVO.getPage_index(),total+"");
		List<LogEarnVO> incomeAndExpensesList = moneyService.selectIncomeAndExpensesList(logEarnVO);
		if(!"1".equals(isJSON)){
			request.setAttribute("awardList",awardList);
			request.setAttribute("incomeAndExpensesList", incomeAndExpensesList);
			request.setAttribute("token", token);
			request.setAttribute("memberId", member_id);
			request.setAttribute("type", type);
			request.setAttribute("bill_type",bill_type);
			request.setAttribute("award_id",award_id);
			request.setAttribute("os",os);
			request.setAttribute("logEarn", logEarnVO);
			request.setAttribute("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");
			//request.setAttribute("incomeAndExpensesLogOne_url","http://10.0.0.68:8080/v2/money/incomeAndExpensesLogOne");

			//兑换券名称从数据库查出来。
			request.setAttribute("ticket_name",ticket_name);
			return "/app/money/incomeAndExpensesItem";
		}else{
			Map map  =  new HashMap();
			LogEarnVO pagination = moneyService.packPaginationInfo(logEarnVO);
			map.put("pagination", pagination);
			map.put("awardList",awardList);
			map.put("incomeAndExpensesList", incomeAndExpensesList);
			map.put("token", token);
			map.put("memberId", member_id);
			map.put("type", type);
			map.put("bill_type",bill_type);
			map.put("award_id",award_id);
			map.put("os",os);
			map.put("logEarn", logEarnVO);
			map.put("incomeAndExpensesLogOne_url",host+version+"/money/incomeAndExpensesLogOne");
			map.put("ticket_name",ticket_name);
			 
		    response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	      return null;
		}
	}	
	
	
}

